package com.yanqu.road.dao.impl.activity.bowart;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.activity.bowart.BowArtJianBaRingInfo;
import com.yanqu.road.entity.activity.bowart.BowArtMingZhongScoreInfo;
import com.yanqu.road.utils.string.StringUtils;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class BowArtConfigDaoImpl extends TempDao {

    public static String getBowArtJianBaScoreInfoSql = "select * from t_s_activity_jianba_score where activityId = ? order by id";
    public List<BowArtJianBaRingInfo> getBowArtJianBaScoreInfo(int activityId) {
        ResultSet rs = null;
        CallableStatement call = null;
        List<BowArtJianBaRingInfo> result = new ArrayList<>();
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getBowArtJianBaScoreInfoSql);
            call.setInt(1, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                BowArtJianBaRingInfo bowArtJianBaScoreInfo = new BowArtJianBaRingInfo();
                bowArtJianBaScoreInfo.setId(rs.getInt("id"));
                bowArtJianBaScoreInfo.setName(rs.getString("name"));
                bowArtJianBaScoreInfo.setRadius(StringUtils.stringToIntegerList(rs.getString("radius"), ","));
                bowArtJianBaScoreInfo.setIntegral(rs.getInt("integral"));
                bowArtJianBaScoreInfo.setRing(rs.getInt("ring"));
                result.add(bowArtJianBaScoreInfo);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return result;
    }


    public static String getBowArtMingZhongScoreInfoSql = "select * from t_s_activity_mingzhong_score where activityId = ? order by id";
    public List<BowArtMingZhongScoreInfo> getBowArtMingZhongScoreInfo(int activityId) {
        ResultSet rs = null;
        CallableStatement call = null;
        List<BowArtMingZhongScoreInfo> result = new ArrayList<>();
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getBowArtMingZhongScoreInfoSql);
            call.setInt(1, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                BowArtMingZhongScoreInfo bowArtMingZhongScoreInfo = new BowArtMingZhongScoreInfo();
                bowArtMingZhongScoreInfo.setId(rs.getInt("id"));
                bowArtMingZhongScoreInfo.setName(rs.getString("name"));
                bowArtMingZhongScoreInfo.setNum(StringUtils.stringToIntegerList(rs.getString("num"), ","));
                bowArtMingZhongScoreInfo.setIntegral(rs.getInt("integral"));
                result.add(bowArtMingZhongScoreInfo);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return result;
    }
}
